﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Reflection;

namespace mxplay
{
    public class DisplayNameLocalizedAttribute : DisplayNameAttribute
    {
        private PropertyInfo name_property;
//        private Type resource_type;

        public DisplayNameLocalizedAttribute(string resource_key, Type resource_type)
            : base(resource_key)
        {
        	name_property = resource_type.GetProperty(resource_key, BindingFlags.Static | BindingFlags.NonPublic);
        }

//        public Type ResourceType
//        {
//            get { return resource_type; }
//            set
//            {
//                resource_type = value;
//                name_property = resource_type.GetProperty(base.DisplayName, BindingFlags.Static | BindingFlags.NonPublic);
//            }
//        }

        public override string DisplayName
        {
            get
            {
                if (name_property == null) return base.DisplayName;
                return (string)name_property.GetValue(name_property.DeclaringType, null);
            }
        }
    }

    public class DescriptionLocalizedAttribute : DescriptionAttribute
    {
        private PropertyInfo name_property;

        public DescriptionLocalizedAttribute(string resource_key, Type resource_type)
            : base(resource_key)
        {
            name_property = resource_type.GetProperty(resource_key, BindingFlags.Static | BindingFlags.NonPublic);
        }

        public override string Description
        {
            get
            {
                if(name_property==null) return base.Description;
                return (string)name_property.GetValue(name_property.DeclaringType, null);
            }
        }
    }

    public class CategoryLocalizedAttribute : CategoryAttribute
    {
        private PropertyInfo name_property;

        public CategoryLocalizedAttribute(string resource_key,Type resource_type)
            : base(resource_key)
        {
            name_property = resource_type.GetProperty(resource_key, BindingFlags.Static | BindingFlags.NonPublic);
        }

        protected override string GetLocalizedString(string value)
        {
            if(name_property==null) return base.GetLocalizedString(value);
            return (string)name_property.GetValue(name_property.DeclaringType, null);
        }
    }

}
